package com.wafersystems.springbootdemo.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 过滤器
 */
@Slf4j
@WebFilter(filterName = "myFiletr", urlPatterns = "/*")
public class AuthFilter implements Filter {

    /**
     * 初始化
     *
     * @param filterConfig
     * @throws ServletException
     */
    @Override
    public void init(FilterConfig filterConfig) {
        // 初始化
    }

    /**
     * doFilter
     *
     * @param servletRequest  -
     * @param servletResponse -
     * @param filterChain     -
     * @throws IOException      -
     * @throws ServletException -
     */
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
                         FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        String url = request.getServletPath();
        String actuator = "/actuator";
        if(!url.startsWith(actuator)){
            log.info("当前拦截的url为：" + url);
        }
        filterChain.doFilter(servletRequest, servletResponse);
        return;
    }

    @Override
    public void destroy() {
    }
}
